define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'branch/index' + location.search,
                    add_url: 'branch/add',
                    edit_url: 'branch/edit',
                    multi_url: 'branch/multi',
                    import_url: 'branch/import',
                    //importBuilding_url: 'branch/import_branch',
                    table: 'branch',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                showToggle: false,
                showColumns: false,
                visible: false,
                showExport: false,
                search:false,
                columns: [
                    [
                        {field: 'id', title: __('Id'), operate: false},
                        //{field: 'admin.nickname', title: __('Admin_id'), operate: false},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        //{field: 'admin_name', title: __('Admin_name'), operate: false},
                        //{field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        //{field: 'address', title: __('Address'), operate: false},
                        {field: 'staff_count', title: __('员工数量'), operate: false},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            /*buttons: [
                                {
                                    name: '批量导入员工',
                                    text: '批量导入员工',
                                    title: '批量导入员工',
                                    classname: 'btn btn-xs btn-warning btn-dialog',
                                    icon: 'fa fa-upload',
                                    url: 'staff/import_staff'
                                }
                            ],*/
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        import_branch: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
